﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Profile;

namespace WebSite.cn
{
    public partial class hotpro :  BasePage
    {
        // Fields

        public string content = "";
        public string sPriceName = "";
        public string linkPrice = string.Empty;
        public string sLoginMessage = "<font size='2'>&nbsp;温馨提示：请登录并充值后，选取您要兑换的商品！</font></br>";

        protected CustomList.CustomList productsList;

        // Methods
        private void Bind()
        {
           // this.productsList.PageSize = Convert.ToInt32(info.info1("", "homeshowpnum5"));
            DataTable table = SQLAccess.GreatDs("select shuxiname from DB_Shuxintype where shuxinid=" + re.replace(base.Request.QueryString["sid"]) + "").Tables[0];
            if (table.Rows.Count > 0)
            {
                this.content = table.Rows[0][0].ToString();
            }
        }

        void BindLinkPrice()
        {
            string sHref = "hotpro.aspx?sid=" + (Request.QueryString["sid"] == null? "" : Request.QueryString["sid"])
                           + "&typeid=" +( Request.QueryString["typeid"] == null ? "" : Request.QueryString["typeid"]) +"&priceid=";
            string sClass1 = "";
            string sClass2 = "";
            string sClass3 = "";
            string sClass4 = "";
            if (Request.QueryString["priceid"] == "1") sClass1 = "currentSelect";
            else if (Request.QueryString["priceid"] == "2") sClass2 = "currentSelect";
            else if (Request.QueryString["priceid"] == "3") sClass3 = "currentSelect";
            else if (Request.QueryString["priceid"] == "4") sClass4 = "currentSelect";
            string linkPriceFormat = "<a href='{0}' class='{4}'>0-100元</a>  &nbsp;<a href='{1}' class='{5}'>101-300元</a>   &nbsp; <a href='{2}' class='{6}'>301-600元</a>  &nbsp; <a href='{3}' class='{7}'>600元以上</a>";
           linkPrice = string.Format(linkPriceFormat,
                                      sHref + "1"
                                      , sHref + "2"
                                      , sHref + "3"
                                      , sHref + "4"
                                      , sClass1
                                      , sClass2
                                      , sClass3
                                      , sClass4);
                                      
        }

        public void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if ((base.Request.QueryString["sid"] != null) && ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem)))
            {
                Label label = (Label)e.Item.FindControl("price");
                Label label2 = (Label)e.Item.FindControl("Label1");
                Image image = (Image)e.Item.FindControl("Image1");
                if ((label.Text == "0") || (label.Text == "0.00"))
                {
                    label.Text = label2.Text;
                }
                if (image.ImageUrl.ToString() == "")
                {
                    image.ImageUrl = "../uploadfile/banner/" + info.info1("", "shopmopic");
                }
                else
                {
                    image.ImageUrl = "../uploadfile/product/" + image.ImageUrl.ToString();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Session["backHref"] = Request.Url.PathAndQuery;
            if (!base.IsPostBack && (base.Request.QueryString["sid"] != null))
            {
                sPriceName = base.Request.QueryString["sid"] == "3" ? "零售价:" : "兑换价:";
                this.BindLinkPrice();
                this.Bind();
            }
        }

        protected void PageChanged(object sender, DataGridPageChangedEventArgs e)
        {
            this.productsList.CurrentPageIndex = e.NewPageIndex;
            string sql = "SELECT proid,proname,proprice1,proprice3,proprice4,propic2,typeid FROM DB_Shoppro where visible=1 and proisshow=1 and visible=1 and isnull(proku1,0)>0  ";
            if (base.Request.QueryString["sid"] != null)
            {
                if (re.replace(base.Request.QueryString["sid"]) == "1")
                {
                    sql = sql + " and proisnew1=1";
                }
                if (re.replace(base.Request.QueryString["sid"]) == "2")
                {
                    sql = sql + " and proisnew2=1";
                }
                if (re.replace(base.Request.QueryString["sid"]) == "3")
                {
                    sql = sql + " and proisnew3=1";
                }
                if (re.replace(base.Request.QueryString["sid"]) == "4")
                {
                    sql = sql + " and proisnew4=1";
                } 
            }
            if (!string.IsNullOrEmpty(Request.QueryString["typeid"]))
            {
                sql = sql + " and typeid=" + Request.QueryString["typeid"];
            }


            if (!string.IsNullOrEmpty(Request.QueryString["priceid"]))
            {
                if (Request.QueryString["priceid"] == "1")
                {
                    sql = sql + " and proprice1>0 and proprice1<=100 ";
                }
                else if (Request.QueryString["priceid"] == "2")
                {
                    sql = sql + " and proprice1>100 and proprice1<=300 ";
                }
                else if (Request.QueryString["priceid"] == "3")
                {
                    sql = sql + " and proprice1>300 and proprice1<=600 ";
                }
                else if (Request.QueryString["priceid"] == "4")
                {
                    sql = sql + " and proprice1>600 ";
                }

                sql = sql + " order by proprice1";
            }
            else
            {

                sql = sql + " order by proorder asc,proid desc ";
            }


            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.productsList.DataSource = table.DefaultView;
            this.productsList.DataBind();
        }



    }
}